<?php
if(!$login_do) include("config.php");
if($_POST['session_id']){
	//////////////////////////////////////////////////////////////////////////////////////
	//获取姓名学号
	$snoopy1 = new Snoopy;
	//模拟HEADER
	$snoopy1->cookies['ASP.NET_SessionId'] = $_SESSION["ASP_NET_SessionId"];
	//获取分析表单
	$snoopy1->fetch($tableurl);
	$res1 = $snoopy1->results;

	//超时返回
	if ($snoopy1->status != '200' || $snoopy1->timed_out) {
    	echo json_err(1,"页面获取超时！");
    	return;
	}

	$res1_html = new simple_html_dom();
	$res1_html->load($res1);
	$table_trs  = $res1_html->find('table.GridViewStyle tr');
	$info_data = [];
	$info_title= [];
	foreach ($table_trs as $key => $value){
		if($key==0){
			$res1_tds = $value->find('th');
			foreach ($res1_tds as $td_key => $td){
				$info_title[] = trim(strip_tags($td->innertext));
				if($td_key == 6){
					$info_title[] = "开始周";
					$info_title[] = "结束周";
					$info_title[] = "星期";
					$info_title[] = "课节";
				}
			}
		}else{
			$res1_tds = $value->find('td');
			$res1_tds_data = [];
			foreach ($res1_tds as $td_key => $td){
				$res1_tds_data[] = trim(strip_tags($td->innertext));
				if($td_key == 6){
					$week_data = trim(strip_tags($td->innertext));
					$week_data_arr = explode(':', $week_data);
					$week_se_arr   = explode('-', str_replace(["第","周"],"",$week_data_arr[0]));
					$res1_tds_data[] = $week_se_arr[0];
					$res1_tds_data[] = $week_se_arr[1];
					$week_d_arr   = explode(' ', str_replace(["星期","上午","下午","晚上"],"",$week_data_arr[2]));
					$res1_tds_data[] = $week_d_arr[0];
					$res1_tds_data[] = $week_d_arr[1];
				}
			}
			$info_data[] = $res1_tds_data;
			if(count($week_d_arr)==4){
				$res1_tds_data[9]  = $week_d_arr[2];
				$res1_tds_data[10] = $week_d_arr[3];
				$info_data[] = $res1_tds_data;
			}
		}
	}
	$table = ["title"=>$info_title,"data"=>$info_data];

	//////////////////////////////////////////////////////////////////////////////////////
	//noapi调用
	if(!empty($_POST['noapi'])){
		//echo "姓名：".$xm."    学号：".$xh;
		echo json_encode($table);
		return;
	}
	echo json_encode($table);
	return;

}else{
	echo json_err(2,'提交数据不全!');
	return;
}
?>